﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Security.Cryptography;
using System.IO;
using System.Text;

using CE.User;
using CE.Global;
using CE.Database;
using CE.Provider;
using CE.TravelInsurance;
using CE.Company;
using CE.Mail;
using CE.InputOut;
using CE.Image;
using CE.AreaCountry;


public partial class travel_insurance_email_this : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[General.TAId] != null && Session[General.TAUserName] != null)
        {
            LoadSummary();
            if (Cache["TAResultsQuotes" + Session[General.TAId].ToString()] == null)
            {
                Response.Redirect("/travel-insurance/");
            }
        }
        else
        {
            Response.Redirect("/travel-insurance/");
        }


        if (Session["ImageCount"] != null)
        {
            if (Convert.ToInt32(Session["ImageCount"].ToString()) > 5)
            {
                lblMessage.Text = "Please try after a few moment! You are session has been locked!";
                btnEmailThis.Enabled = false;
                btnNewImage.Enabled = false;
                txtEmail.Enabled = false;
                txtSecurityCode.Enabled = false;
                //Response.Redirect("usermessage.aspx?mt=um&ec=1993");
            }
            else
            {
                lblMessage.Text = "";
                btnEmailThis.Enabled = true;
                btnNewImage.Enabled = true;
                txtEmail.Enabled = true;
                txtSecurityCode.Enabled = true;
            }
        } 


        if (!Page.IsPostBack)
        {
            if (Session[General.TAUserName].ToString() != "")
            {
                txtFullName.Text = Session[General.TAUserName].ToString();
                txtEmail.Text = Session[General.TAEmail].ToString();

                if (Session["ImageCount"] != null)
                {
                    if (Convert.ToInt32(Session["ImageCount"].ToString()) <= 5)
                    {
                        CreateUpdateImageAndSession();
                    }
                }
                else
                {
                    CreateUpdateImageAndSession();
                }
            }


        }

    }

    protected void btnEmailThis_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            if (Session[CE.Global.General.SecurityCheckWord] != null)
            {
                string _usrText = txtSecurityCode.Text.ToUpper();
                string _imgText = Session[CE.Global.General.SecurityCheckWord].ToString().ToUpper();

                if (_usrText == _imgText)
                {
                    if (SendMail())
                    {
                        TAUserOptionLog();

                        Response.Redirect("email-usermessage.aspx");

                    }

                }
                else
                {
                    lblMessage.Text = "Wrong security check!";
                    CreateUpdateImageAndSession();
                }
            }
            else
            {
                lblMessage.Text = "Security Check code was expired. Please try again.";
                CreateUpdateImageAndSession();
            }

        }

    }

    protected void btnBack_Click(object sender, EventArgs e)
    {
        if (Session["TAFromSummary"] != null)
        {
            if (Session["TAFromSummary"].ToString().Trim() == "1")
            {
                Response.Redirect("results.aspx");
            }
            else
            {
                Response.Redirect("results-details.aspx");
            }
        }
        else
        {
            Response.Redirect("results.aspx");
        }
    }

    private bool SendMail()
    {
        string userfirstname = txtFullName.Text;

        bool _retVal = false;

        string _emailTo = txtEmail.Text;
        string _customername = userfirstname;
        string _emailSubject = "Your Travel Insurance Quotes on CompareXpress";
        string _mailBody = "";
        string _currentDomainUrl = "http://" + HttpContext.Current.Request.Url.Host.ToString();
        string imgLogoUrl = _currentDomainUrl + CE.Configuration.MyConfigurationManager.GetAppSettingValue("LogoPath");

        _mailBody = "<body class='email_body'>";
        _mailBody += "<style type='text/css'>";
        _mailBody += ".email_body {background:white;margin:0; padding:0; color:#4c4c4c; font-family:Arial, Helvetica, sans-serif; font-size:0.85em;}";
        _mailBody += "a {text-decoration:underline;color:#2c95cc;} ";
        _mailBody += "#email_container {margin:0 auto;padding:20px;width:600px; height:auto;} ";
        _mailBody += "#email_body {width:100%; text-align: left !important;} ";
        _mailBody += ".email_pad10px {padding:10px;} ";
        _mailBody += ".email_results td {width:33%;} ";
        _mailBody += "</style>";
        _mailBody += "<center>";

        _mailBody += "<table cellpadding='0' cellspacing='0' border='0' style='padding:20px;' width='600'>";
        _mailBody += "<tr><td width='360'><a href='http://www.comparexpress.com/travel-insurance/' target='_blank'><img src='" + _currentDomainUrl + "/images/email/header_quote.png' width='596' height='187' alt='CompareXpress' border='0' /></a></td></tr>";
        _mailBody += "<tr><td style='padding-left:45px; padding-right:45px;'><strong>Dear " + userfirstname.ToUpper() +",</strong><br/><br/>";
        _mailBody += "Thank you for using CompareXpress Travel Insurance Comparison Engine:<br/><br/>";
        _mailBody += "Please find below a copy of your requested quote.<br/><br/>";

        _mailBody += "Destination: " + lblDestination.Text + "<br/>";
        _mailBody += "Travel Date: " + lblTravelDate.Text + "<br/>";
        _mailBody += "No. of Traveller/s: " + lblTravellers.Text + "<br/>";
        _mailBody += "Trip Type: " + lblTripType.Text + "<br/>";
        _mailBody += "Type of Policy: " + lblPolicy.Text + "<br/><br/>";

        DataView dvResults = new DataView((DataTable)Cache["TAResultsQuotes" + Session[General.TAId].ToString()]);

        _mailBody += "<table cellpadding='5' cellspacing='0' border='0' width='546px' class='table_details'>";

        string strTAId = Session[General.TAResultId].ToString();
        dvResults.RowFilter = " TAInsID in (" + strTAId + ")";

        DataTable dtResults = dvResults.ToTable();


        if (dtResults.Rows.Count > 0)
        {
            string _providercompanyid = dtResults.Rows[0]["providercompanyid"].ToString();
            string insurername = dtResults.Rows[0]["InsurerName"].ToString();
            //logo
            string logourl = "/images/public/logo/";
            if (_providercompanyid == "23")
            {
                logourl += "hsbc.png";
                insurername = "HSBC Insurance";
            }
            if (_providercompanyid == "24")
            {
                logourl += "rsa.png";
                insurername = "RSA Insurance";
            }
            else if (_providercompanyid == "29")
            {
                logourl += "liberty.png";
                insurername = "Liberty Insurance";
            }
            else if (_providercompanyid == "30")
            {
                logourl += "etiqa.png";
                insurername = "Etiqa Insurance";
            }
            else if (_providercompanyid == "31")
            {
                logourl += "chartis.png";
                insurername = "Chartis Insurance";
            }
            else if (_providercompanyid == "34")
            {
                logourl += "chinataiping.png";
                insurername = "China Taiping Insurance";
            }
            else if (_providercompanyid == "35")
            {
                logourl += "eq.png";
                insurername = "EQ Insurance";
            }
            else if (_providercompanyid == "36")
            {
                logourl += "ace.png";
                insurername = "ACE Insurance";
            }
            else if (_providercompanyid == "37")
            {
                logourl += "1cover.png";
                insurername = "1Cover Insurance";
            }
            else if (_providercompanyid == "38")
            {
                logourl += "directasia.png";
                insurername = "DirectAsia Insurance";
            }
            _mailBody += "<tr>";
            _mailBody += "<td width='45%'></td>";
            _mailBody += "<td width='55%' align='center' style='background:#e0e0e0; border-bottom:white 1px dashed;'><img src='" + _currentDomainUrl + logourl + "' width='130' style='padding:3px;'/></td>";
            _mailBody += "</tr>";

            //insurer name
            _mailBody += "<tr>";
            _mailBody += "<td><strong>Insurer</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5; color:white;'><strong>" + insurername + "</strong></td>";
            _mailBody += "</tr>";

            //premium
            string premium = "";
            //if (_providercompanyid == "36")
            //{
            //    double _discounted = Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()) * 0.9;
            //    premium = "<small>" + String.Format("${0:0,0.00}", _discounted) + "</small>";
            //    premium += "  <s>" + String.Format("${0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString())) + "</s>";
            //}
            //else
            //{
                premium = String.Format("${0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()));
            //}

            _mailBody += "<tr>";
            _mailBody += "<td align='left' style='background:#d5d5d5' ><strong>Price</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5; color:black; font-size:20px;'><strong>" + premium + "</strong></td>";
            _mailBody += "</tr>";

            if (_providercompanyid == "34") //pdf only for all benefits
            {
                //PDF benefit               
                string benefitsurl = _currentDomainUrl + "/policy_docs/ChinaTaiping/Coverage.pdf";
                string viewbenefitspdf = "<a href='" + benefitsurl + "' ><img src='" + _currentDomainUrl + "/images/icon/pdf.png'  alt='policy wordings' width='23' alt='NA' border='0'/></a>";

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Benefits</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + viewbenefitspdf + "</td>";
                _mailBody += "</tr>";
            }
            else
            {

                //Personal Accident adult
                string PAadult = "";
                float _fPAadult = 0;
                if (dtResults.Rows[0]["DTPD_LessYr70"].ToString() != "")
                {
                    _fPAadult = Convert.ToSingle(dtResults.Rows[0]["DTPD_LessYr70"].ToString());
                }

                if (_fPAadult > 0.0f)
                {
                    string _PAadultAmount = String.Format("${0:0,0}", _fPAadult);
                    PAadult = _PAadultAmount;
                }
                else
                {
                    PAadult = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Personal Accident </strong>(adult)</td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + PAadult + "</td>";
                _mailBody += "</tr>";

                //Personal Accident >70
                string PA70 = "";
                float _fPA70 = 0;
                if (dtResults.Rows[0]["DTPD_AboveYr70"].ToString() != "")
                {
                    _fPA70 = Convert.ToSingle(dtResults.Rows[0]["DTPD_AboveYr70"].ToString());
                }

                if (_fPA70 > 0.0f)
                {
                    string _PA70 = String.Format("${0:0,0}", _fPA70);
                    PA70 = _PA70;
                }
                else
                {
                    PA70 = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Personal Accident</strong> (> 70)</td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + PA70 + "</td>";
                _mailBody += "</tr>";

                //Double Indemnity adult
                string DIadult = "";
                float _fDIadult = 0;
                if (dtResults.Rows[0]["DIPC_LessYr70"].ToString() != "")
                {
                    _fDIadult = Convert.ToSingle(dtResults.Rows[0]["DIPC_LessYr70"].ToString());
                }

                if (_fDIadult > 0.0f)
                {
                    string _DIadult = String.Format("${0:0,0}", _fDIadult);
                    DIadult = _DIadult;
                }
                else
                {
                    DIadult = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Double Indemnity </strong>(adult)</td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + DIadult + "</td>";
                _mailBody += "</tr>";


                //Double Indemnity >70
                string DI70 = "";
                float _fDI70 = 0;
                if (dtResults.Rows[0]["DIPC_AboveYr70"].ToString() != "")
                {
                    _fDI70 = Convert.ToSingle(dtResults.Rows[0]["DIPC_AboveYr70"].ToString());
                }

                if (_fDI70 > 0.0f)
                {
                    string _DI70 = String.Format("${0:0,0}", _fDI70);
                    DI70 = _DI70;
                }
                else
                {
                    DI70 = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Double Indemnity </strong>(> 70)</td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + DI70 + "</td>";
                _mailBody += "</tr>";


                //MEd Expenses adult
                string MedExpenseAdult = "";
                float _fMedExpAdult = 0;
                if (dtResults.Rows[0]["MedExp_LessYr70"].ToString() != "")
                {
                    _fMedExpAdult = Convert.ToSingle(dtResults.Rows[0]["MedExp_LessYr70"].ToString());
                }

                if (_fMedExpAdult > 0.0f)
                {
                    string _MedExpAdult = String.Format("${0:0,0}", _fMedExpAdult);
                    MedExpenseAdult = _MedExpAdult;

                    if (_providercompanyid == "38")
                    {
                        MedExpenseAdult += "<br/>TCM: $300";
                    }
                    else if (_providercompanyid == "38")
                    {
                        MedExpenseAdult += "<br/>TCM: $750";
                    }
                }
                else
                {
                    MedExpenseAdult = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Medical Expenses </strong>(adult)</td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + MedExpenseAdult + "</td>";
                _mailBody += "</tr>";

                //Med Expenses > 70
                string MedExpense70 = "";
                float _fMedExp70 = 0;
                if (dtResults.Rows[0]["MedExp_AboveYr70"].ToString() != "")
                {
                    _fMedExp70 = Convert.ToSingle(dtResults.Rows[0]["MedExp_AboveYr70"].ToString());
                }

                if (_fMedExp70 > 0.0f)
                {
                    string _MedExp70 = String.Format("${0:0,0}", _fMedExp70);
                    MedExpense70 = _MedExp70;

                    if (_providercompanyid == "38")
                    {
                        MedExpense70 += "<br/>TCM: $300";
                    }
                    else if (_providercompanyid == "36")
                    {
                        MedExpense70 += "<br/>TCM: $750";
                    }
                }
                else
                {
                    MedExpense70 = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Medical Expenses </strong>(> 70)</td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + MedExpense70 + "</td>";
                _mailBody += "</tr>";


                //Emergency Med Evac
                string EmergMedEvac = "";
                float _fEmergMedEvac = 0;
                if (dtResults.Rows[0]["EmMedEval"].ToString() != "")
                {
                    _fEmergMedEvac = Convert.ToSingle(dtResults.Rows[0]["EmMedEval"].ToString());
                }

                if (_fEmergMedEvac > 0.0f)
                {
                    string _EmergMedEvac = String.Format("${0:0,0}", _fEmergMedEvac);
                    EmergMedEvac = _EmergMedEvac;

                    if (_providercompanyid == "38")
                    {
                        EmergMedEvac += "<br/>(combined cover with Repatriation & Funeral Expense)";
                    }
                }
                else
                {
                    EmergMedEvac = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Emergency Medical Evacuation </strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + EmergMedEvac + "</td>";
                _mailBody += "</tr>";

                //Repatriation & Funeral Expenses
                string Repatriation = "";
                float _fRepatriation = 0;
                if (dtResults.Rows[0]["BCR"].ToString() != "")
                {
                    _fRepatriation = Convert.ToSingle(dtResults.Rows[0]["BCR"].ToString());
                }
                if (dtResults.Rows[0]["Info5"].ToString() == "True")
                {
                    Repatriation = "<font color=Red>*as charged</font>";

                    if (_providercompanyid == "36")
                    {
                        Repatriation = "<font color=Red>Unlimited</font>";
                    }
                }
                else
                {
                    if (_fRepatriation > 0.0f)
                    {
                        string _Repatriation = String.Format("${0:0,0}", _fRepatriation);
                        Repatriation = _Repatriation;

                        if (_providercompanyid == "38")
                        {
                            Repatriation += "<br/>(combined cover with Emergency Medical Evacuation)";
                        }
                    }
                    else
                    {
                        Repatriation = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                    }
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Repatriation & Funeral Expenses</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + Repatriation + "</td>";
                _mailBody += "</tr>";


                //Hospital Income
                string HospitalIncome = "";
                float _fHospitalIncome = 0;
                if (dtResults.Rows[0]["HospIncome"].ToString() != "")
                {
                    _fHospitalIncome = Convert.ToSingle(dtResults.Rows[0]["HospIncome"].ToString());
                }

                if (_fHospitalIncome > 0.0f)
                {
                    string _HospitalIncome = String.Format("${0:0,0}", _fHospitalIncome);
                    HospitalIncome = _HospitalIncome + "/day <br/> max " + String.Format("{0:c0}", int.Parse(dtResults.Rows[0]["Ninfo4"].ToString()));

                }
                else
                {
                    HospitalIncome = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Hospital Income</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + HospitalIncome + "</td>";
                _mailBody += "</tr>";

                //Pregnancy
                string Pregnancy = "";
                float _fPregnancy = 0;
                if (dtResults.Rows[0]["NInfo3"].ToString() != "")
                {
                    _fPregnancy = Convert.ToSingle(dtResults.Rows[0]["NInfo3"].ToString());
                }

                if (_fPregnancy > 0.0f)
                {
                    string _Pregnancy = String.Format("${0:0,0}", _fPregnancy);
                    Pregnancy = _Pregnancy;

                    if (_providercompanyid == "38")
                    {
                        Pregnancy = "Covered under Medical Expenses (adult)";
                    }
                }
                else
                {
                    Pregnancy = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Pregnancy-Related Illness </strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + Pregnancy + "</td>";
                _mailBody += "</tr>";


                //Overseas Compa Visit
                string OverseasCompVisit = "";
                float _fOverseasCompVisit = 0;
                if (dtResults.Rows[0]["CompassVisit"].ToString() != "")
                {
                    _fOverseasCompVisit = Convert.ToSingle(dtResults.Rows[0]["CompassVisit"].ToString());
                }

                if (_fOverseasCompVisit > 0.0f)
                {
                    string _OverseasCompVisit = String.Format("${0:0,0}", _fOverseasCompVisit);
                    OverseasCompVisit = _OverseasCompVisit;

                }
                else
                {
                    OverseasCompVisit = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Overseas Compassionate Visit</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + OverseasCompVisit + "</td>";
                _mailBody += "</tr>";


                //Child Guard
                string ChildGuard = "";
                float _fChildGuard = 0;
                if (dtResults.Rows[0]["ChildCare"].ToString() != "")
                {
                    _fChildGuard = Convert.ToSingle(dtResults.Rows[0]["ChildCare"].ToString());
                }

                if (_fChildGuard > 0.0f)
                {
                    string _ChildGuard = String.Format("${0:0,0}", _fOverseasCompVisit);
                    ChildGuard = _ChildGuard;

                }
                else
                {
                    ChildGuard = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Child Guard</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + ChildGuard + "</td>";
                _mailBody += "</tr>";


                //Personal Liablity
                string PersonalLiability = "";
                float _fPersonalLiability = 0;
                if (dtResults.Rows[0]["PersonalLiability"].ToString() != "")
                {
                    _fPersonalLiability = Convert.ToSingle(dtResults.Rows[0]["PersonalLiability"].ToString());
                }

                if (_fPersonalLiability > 0.0f)
                {
                    string _PersonalLiability = String.Format("${0:0,0}", _fPersonalLiability);
                    PersonalLiability = _PersonalLiability;

                }
                else
                {
                    PersonalLiability = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Personal Liability</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + PersonalLiability + "</td>";
                _mailBody += "</tr>";


                //Loss Baggage & Personal Effects
                string LossBaggage = "";
                float _fLossBaggage = 0;
                if (dtResults.Rows[0]["BagPerEffect"].ToString() != "")
                {
                    _fLossBaggage = Convert.ToSingle(dtResults.Rows[0]["BagPerEffect"].ToString());
                }

                if (_fLossBaggage > 0.0f)
                {
                    string _LossBaggage = String.Format("${0:0,0}", _fLossBaggage);
                    LossBaggage = _LossBaggage;

                    if (_providercompanyid == "38")
                    {
                        LossBaggage += "<br/>($500 per article/laptop/mobile phone or PDA)";
                    }

                }
                else
                {
                    LossBaggage = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Loss Baggage & Personal Effects</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + LossBaggage + "</td>";
                _mailBody += "</tr>";

                //OverseasBaggage
                string OverseasBaggage = "";
                float _fOverseasBaggage = 0;
                if (dtResults.Rows[0]["BagDelay"].ToString() != "")
                {
                    _fOverseasBaggage = Convert.ToSingle(dtResults.Rows[0]["BagDelay"].ToString());
                }

                if (_fOverseasBaggage > 0.0f)
                {
                    string _OverseasBaggage = String.Format("${0:0,0}", _fOverseasBaggage) + "/" + dtResults.Rows[0]["Ninfo5"].ToString() + "-hour delay";
                    _OverseasBaggage += "<br/> max " + String.Format("{0:c0}", int.Parse(dtResults.Rows[0]["Ninfo6"].ToString()));

                    OverseasBaggage = _OverseasBaggage;

                    if (_providercompanyid == "38")
                    {
                        OverseasBaggage = String.Format("{0:c0}", int.Parse(dtResults.Rows[0]["Ninfo6"].ToString()));
                    }

                }
                else
                {
                    OverseasBaggage = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Overseas Baggage Delay</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + OverseasBaggage + "</td>";
                _mailBody += "</tr>";


                //Trip Cancellation
                string TripCancellation = "";
                float _fTripCancellation = 0;
                if (dtResults.Rows[0]["DepositTripCancel"].ToString() != "")
                {
                    _fTripCancellation = Convert.ToSingle(dtResults.Rows[0]["DepositTripCancel"].ToString());
                }

                if (_fTripCancellation > 0.0f)
                {
                    string _TripCancellation = String.Format("${0:0,0}", _fTripCancellation);
                    TripCancellation = _TripCancellation;

                }
                else
                {
                    TripCancellation = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Trip Cancellation</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + TripCancellation + "</td>";
                _mailBody += "</tr>";


                //Trip Curtailment
                string TripCurtailment = "";
                float _fTripCurtailment = 0;
                if (dtResults.Rows[0]["Curtailment"].ToString() != "")
                {
                    _fTripCurtailment = Convert.ToSingle(dtResults.Rows[0]["Curtailment"].ToString());
                }

                if (_fTripCurtailment > 0.0f)
                {
                    string _TripCurtailment = String.Format("${0:0,0}", _fTripCurtailment);
                    TripCurtailment = _TripCurtailment;

                    if (_providercompanyid == "38")
                    {
                        TripCurtailment = TripCancellation;
                    }

                }
                else
                {
                    TripCurtailment = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Trip Curtailment</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + TripCurtailment + "</td>";
                _mailBody += "</tr>";


                //Overseas Travel Delay
                string OverseasTD = "";
                float _fOverseasTD = 0;
                if (dtResults.Rows[0]["TravelDelay"].ToString() != "")
                {
                    _fOverseasTD = Convert.ToSingle(dtResults.Rows[0]["TravelDelay"].ToString());
                }

                if (_fOverseasTD > 0.0f)
                {
                    string _OverseasTD = String.Format("${0:0,0}", _fOverseasTD) + "/" + dtResults.Rows[0]["Ninfo7"].ToString() + "-hour delay";
                    _OverseasTD += "<br/> max " + String.Format("{0:c0}", int.Parse(dtResults.Rows[0]["Ninfo8"].ToString()));
                    OverseasTD = _OverseasTD;

                    if (_providercompanyid == "38")
                    {
                        OverseasTD = "$1,000 <br/>($100 per 6 hrs *)<br/>* $50 per 6 hrs for Jetstar and Tiger"; ;
                    }

                }
                else
                {
                    OverseasTD = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Overseas Travel Delay</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + OverseasTD + "</td>";
                _mailBody += "</tr>";

                //Missed Travel Connection
                string MissTravelConn = "";
                float _fMissTravelConn = 0;
                if (dtResults.Rows[0]["MissTravelConnection"].ToString() != "")
                {
                    _fMissTravelConn = Convert.ToSingle(dtResults.Rows[0]["MissTravelConnection"].ToString());
                }

                if (_fMissTravelConn > 0.0f)
                {
                    string _MissTravelConn = String.Format("${0:0,0}", _fMissTravelConn);
                    MissTravelConn = _MissTravelConn;

                }
                else
                {
                    MissTravelConn = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Missed Travel Connection</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + MissTravelConn + "</td>";
                _mailBody += "</tr>";


                //Travel Overbooked
                string TravelOverbook = "";
                float _fTravelOverbook = 0;
                if (dtResults.Rows[0]["TravelOverBook"].ToString() != "")
                {
                    _fTravelOverbook = Convert.ToSingle(dtResults.Rows[0]["TravelOverBook"].ToString());
                }

                if (_fTravelOverbook > 0.0f)
                {
                    string _TravelOverbook = String.Format("${0:0,0}", _fTravelOverbook);
                    TravelOverbook = _TravelOverbook;

                }
                else
                {
                    TravelOverbook = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Travel Overbooked</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + TravelOverbook + "</td>";
                _mailBody += "</tr>";


                //Loss of Personal Money
                string LossMoney = "";
                float _fLossMoney = 0;
                if (dtResults.Rows[0]["PersonalMoney"].ToString() != "")
                {
                    _fLossMoney = Convert.ToSingle(dtResults.Rows[0]["PersonalMoney"].ToString());
                }

                if (_fLossMoney > 0.0f)
                {
                    string _LossMoney = String.Format("${0:0,0}", _fLossMoney);
                    LossMoney = _LossMoney;

                }
                else
                {
                    LossMoney = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Loss of Personal Money</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + LossMoney + "</td>";
                _mailBody += "</tr>";


                //Loss of Travel Documents
                string LossTravelDoc = "";
                float _fLossTravelDoc = 0;
                if (dtResults.Rows[0]["TravelDoc"].ToString() != "")
                {
                    _fLossTravelDoc = Convert.ToSingle(dtResults.Rows[0]["TravelDoc"].ToString());
                }

                if (_fLossTravelDoc > 0.0f)
                {
                    string _LossTravelDoc = String.Format("${0:0,0}", _fLossTravelDoc);
                    LossTravelDoc = _LossTravelDoc;

                }
                else
                {
                    LossTravelDoc = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Loss of Travel Documents</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + LossTravelDoc + "</td>";
                _mailBody += "</tr>";


                //Closure of Travel Agency
                string ClosureAgency = "";
                float _fClosureAgency = 0;
                if (dtResults.Rows[0]["Info3"].ToString() != "")
                {
                    _fClosureAgency = Convert.ToSingle(dtResults.Rows[0]["Info3"].ToString());
                }

                if (_fClosureAgency > 0.0f)
                {
                    string _ClosureAgency = String.Format("${0:0,0}", _fClosureAgency);
                    ClosureAgency = _ClosureAgency;

                }
                else
                {
                    ClosureAgency = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Closure of Travel Agency</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + ClosureAgency + "</td>";
                _mailBody += "</tr>";


                //Home Contents
                string HomeContents = "";
                float _fHomeContents = 0;
                if (dtResults.Rows[0]["FBHCP"].ToString() != "")
                {
                    _fHomeContents = Convert.ToSingle(dtResults.Rows[0]["FBHCP"].ToString());
                }

                if (_fHomeContents > 0.0f)
                {
                    string _HomeContents = String.Format("${0:0,0}", _fHomeContents);
                    HomeContents = _HomeContents;

                    if (_providercompanyid == "23")
                    {
                        if (Session["TripType"].ToString() == "A")
                        {
                            HomeContents = "Optional";
                        }
                    }
                }
                else
                {
                    HomeContents = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Home Contents Protection</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + HomeContents + "</td>";
                _mailBody += "</tr>";


                //Rental Vehicle
                string RentalVehicle = "";
                float _fRentalVehicle = 0;
                if (dtResults.Rows[0]["ACRR"].ToString() != "")
                {
                    _fRentalVehicle = Convert.ToSingle(dtResults.Rows[0]["ACRR"].ToString());
                }

                if (_fRentalVehicle > 0.0f)
                {
                    string _RentalVehicle = String.Format("${0:0,0}", _fRentalVehicle);
                    RentalVehicle = _RentalVehicle;


                }
                else
                {
                    RentalVehicle = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Rental Vehicle Excess</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + RentalVehicle + "</td>";
                _mailBody += "</tr>";


                //Hijack
                string Hijack = "";
                float _fHijack = 0;
                if (dtResults.Rows[0]["Terrorism"].ToString() != "")
                {
                    _fHijack = Convert.ToSingle(dtResults.Rows[0]["Terrorism"].ToString());
                }

                if (_fHijack > 0.0f)
                {
                    string _Hijack = String.Format("${0:0,0}", _fHijack) + "/" + dtResults.Rows[0]["Info1"].ToString() + "-hour";
                    _Hijack += "<br/> max " + String.Format("{0:c0}", int.Parse(dtResults.Rows[0]["Info2"].ToString()));
                    Hijack = _Hijack;

                }
                else
                {
                    Hijack = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Hijack</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + Hijack + "</td>";
                _mailBody += "</tr>";

                //Kidnap / Hostage
                string Kidnap = "";
                float _fKidnap = 0;
                if (dtResults.Rows[0]["KidnapHostage"].ToString() != "")
                {
                    _fKidnap = Convert.ToSingle(dtResults.Rows[0]["KidnapHostage"].ToString());
                }

                if (_fKidnap > 0.0f)
                {
                    string _Kidnap = String.Format("${0:0,0}", _fKidnap);
                    Kidnap = _Kidnap;

                }
                else
                {
                    Kidnap = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Kidnap</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + Kidnap + "</td>";
                _mailBody += "</tr>";

                //Emergency Tel Charges
                string EmtelCharge = "";
                float _fEmtelCharge = 0;
                if (dtResults.Rows[0]["EmTelCharge"].ToString() != "")
                {
                    _fEmtelCharge = Convert.ToSingle(dtResults.Rows[0]["EmTelCharge"].ToString());
                }

                if (dtResults.Rows[0]["Info6"].ToString() != "" && dtResults.Rows[0]["Info6"].ToString() == "True")
                {
                    EmtelCharge = "<font color='red'>*actual cost</font>";
                }
                else
                {
                    if (_fEmtelCharge > 0.0f)
                    {
                        string _EmtelCharge = String.Format("${0:0,0}", _fEmtelCharge);
                        EmtelCharge = _EmtelCharge;

                    }
                    else
                    {
                        EmtelCharge = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                    }
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Emergency Telephone Charges</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + EmtelCharge + "</td>";
                _mailBody += "</tr>";
            }

            //View Policy Wordings
            string _policyId = dtResults.Rows[0]["NInfo1"].ToString();

            ProviderPolicyDocument _policydoc = new ProviderPolicyDocument();
            ProviderPolicyDocumentDB _policydocdb = new ProviderPolicyDocumentDB();

            _policydoc = _policydocdb.GetProviderPolicyDocument(Convert.ToInt64(_policyId));

            string docurl = _currentDomainUrl + _policydoc.UploadPath.Remove(0, 1);
            string viewpolicywordings = "<a href='" + docurl + "' ><img src='" + _currentDomainUrl + "/images/icon/pdf.png'  alt='policy wordings' width='23' alt='NA' border='0'/></a>";

            _mailBody += "<tr>";
            _mailBody += "<td><strong>View Policy Wordings</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + viewpolicywordings + "</td>";
            _mailBody += "</tr>";

        }

        _mailBody += "</table>";
        _mailBody += "<br/><br/>You are also able to view this quote on our website by clicking on the link below. <br/><br/>";
        _mailBody += " <a href='http://www.comparexpress.com/travel-insurance/results-details.aspx?emtaid=" + Session[General.TAId].ToString() + "'>CompareXpress.com</a> <br/><br/>";

        _mailBody += "</td></tr>";
        _mailBody += "<tr><td id='email_footer'><a href='http://www.comparexpress.com' target='_blank'><img src='" + _currentDomainUrl + "/images/email/footer_quote.png' alt='CompareXpress - Partners' width='596' height='174' border='0' /></a>";
        _mailBody += "</td></tr></table>";

        _mailBody += "<hr />";
        _mailBody += "This Quote is subject to the insurer's final confirmation and coverage is only effective when the <br/>";
        _mailBody += "insurer has accepted the risk.<br/>";
        _mailBody += "<br /><i>This is a computer-generated email. Please do not reply to this email.</i>";
        _mailBody += "<hr />";
        _mailBody += "</center></body>";

        if (MyMailManager.SendCRMMessage(_emailTo, _emailSubject, _mailBody))
        {
            _retVal = true;
        }
        else
        {
            _retVal = false;
        }

        return _retVal;
    }

    protected void btnNewImage_Click(object sender, EventArgs e)
    {
        CreateUpdateImageAndSession();
    }

    private void CreateUpdateImageAndSession()
    {
        MyImage myimage = new MyImage();
        string salt = "";

        if (Session[CE.Global.General.SecurityCheckWord] != null)
        {
            salt = myimage.GetRandomWord(Session[CE.Global.General.SecurityCheckWord].ToString());
        }
        else
        {
            if (Session[CE.Global.General.SecurityCheckWord] != null)
            {
                salt = myimage.GetRandomWord(Session[CE.Global.General.SecurityCheckWord].ToString());
            }
            else
            {
                salt = myimage.GetRandomWord("all");
            }
        }

        Session[CE.Global.General.SecurityCheckWord] = salt;
        imgCAPTCHA.ImageUrl = @"~/CAPTCHA/CAPTCHAImageHandler.ashx?id=" + CE.Security.MySecurity.Encrypt(salt, true);
        txtSecurityCode.Text = "";
    }

    private void TAUserOptionLog()
    {
        TAUserOption tauseroption = new TAUserOption();
        TAUserOptionDB tauseroptiondb = new TAUserOptionDB();

        tauseroption.TAUserOptionId = 0;
        tauseroption.TAId = Convert.ToInt64(Session[General.TAId].ToString());
        tauseroption.IsBuyNow = false;
        tauseroption.IsCallMe = false;
        tauseroption.IsEmailMe = false;
        tauseroption.IsEmailThis = true;
        tauseroption.RecipientName = General.ClearScriptTag(txtFullName.Text.Trim());
        tauseroption.RecipientEmailAddress = txtEmail.Text.Trim();
        tauseroption.ViewedDetailId = 0;

        if (Session[General.UserId] != null)
        {
            if (Session[General.UserId].ToString() != "")
                tauseroption.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
            else
                tauseroption.RefCEUserId = 0;
        }
        else
        {
            tauseroption.RefCEUserId = 0;
        }

        tauseroptiondb.Insert(tauseroption);
    }

    protected void LoadSummary()
    {
        Int64 TAId = 0;

        TAApplicantSearchDB _taapplicantsearchdb = new TAApplicantSearchDB();
        TAApplicantSearch _taapplicantsearch = new TAApplicantSearch();

        if (Session[General.TAId] != null)
            TAId = Convert.ToInt64(Session[General.TAId]);

        _taapplicantsearch = _taapplicantsearchdb.GetTAApplicantSearchItem(TAId);

        if (_taapplicantsearch != null)
        {

            lblTripType.Text = GetCoverage(_taapplicantsearch.TripType.ToString());
            lblPolicy.Text = GetPolicy(_taapplicantsearch.PlanType.ToString());
            lblTravelDate.Text = String.Format("{0:dd/MM/yyyy} To {1:dd/MM/yyyy}", _taapplicantsearch.StartDate, _taapplicantsearch.EndDate);
            lblTravellers.Text = (_taapplicantsearch.NoofChilds + _taapplicantsearch.NoofAdults).ToString();


            if (_taapplicantsearch.AreaID != 0)
                lblDestination.Text = GetAreaName(_taapplicantsearch.AreaID);
            else
                lblDestination.Text = GetCountryName(_taapplicantsearch.CountryID);

            
        }
    }

    protected string GetAreaName(Int64 areaid)
    {
        string Area = "";

        AreaInfo _areainfo = new AreaInfo();
        AreaInfoDB _areainfodb = new AreaInfoDB();

        _areainfo = _areainfodb.GetAreaInfo(areaid);

        Area = _areainfo.Description;

        return Area;

    }

    protected string GetCountryName(Int64 countryid)
    {
        string Country = "";

        CountryInfo _countryinfo = new CountryInfo();
        CountryInfoDB _countryinfodb = new CountryInfoDB();

        _countryinfo = _countryinfodb.GetCountryInfo(countryid);

        Country = _countryinfo.Description;

        return Country;

    }

    protected string GetPolicy(string covertype)
    {
        string policy = "family";

        if (covertype == "IND")
        {
            policy = "Individual";
        }
        else if (covertype == "INS")
        {
            policy = "Individual + Spouse";
        }
        else if (covertype == "INC")
        {
            policy = "Individual + Child";
        }
        else if (covertype == "FML")
        {
            policy = "Family";
        }

        return policy;
    }

    protected string GetCoverage(string coverage)
    {
        string cover = "Single Trip";

        if (coverage == "A")
            cover = "Annual Multi-trip";

        return cover;
    }
}
